// app.js
var utils = require('./utils/common');
// import Toast from './miniprogram_npm/@vant/weapp/toast/toast';
App({
  onLaunch() {
    // 获取胶囊信息
    let menuButtonObject = wx.getMenuButtonBoundingClientRect()
    console.log(menuButtonObject)
    // 获取设备信息
    wx.getSystemInfo({
      success: res => {
        console.log(res)
        // 整个导航栏的高度
        let navHeight = menuButtonObject.top + menuButtonObject.height + (menuButtonObject.top - res.statusBarHeight) * 2
        // 导航栏的高度
        let nav = navHeight - res.statusBarHeight

        // 挂载到全区变量 globalData 上
        this.globalData.navHeight = navHeight
        this.globalData.nav = nav

        // 胶囊与左边的距离
        this.globalData.menuLeft = menuButtonObject.left
        // 胶囊的高度
        this.globalData.menuHeight = menuButtonObject.height
        // 胶囊距离顶部的高度
        this.globalData.menuBot = menuButtonObject.top - res.statusBarHeight
        // 整个设备的宽度
        this.globalData.windowWidth = res.windowWidth
      },
      fail: err => {
        console.log(err)
      }
    })
    // 展示本地存储能力
    // const logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)


    // 登录
    // const token = wx.getStorageSync('token')
    // console.log(token);
    // this.globalData.request('/api/authorize/user/info', {}, "POST", ).then(res => {
    //   console.log("++++++++", res);
    //   Toast('我是提示文案，建议不超过十五字~');
    //   if (res.code !== 200) {

    //   }
    // })

  },
  // watch: function (ctx, obj) {
  //   Object.keys(obj).forEach(key => {
  //     this.observer(ctx.data, key, ctx.data[key], function (value) {
  //       obj[key].call(ctx, value)
  //     })
  //   })
  // },
  // // 监听属性，并执行监听函数
  // observer: function (data, key, val, fn) {
  //   Object.defineProperty(data, key, {
  //     configurable: true,
  //     enumerable: true,
  //     get: function () {
  //       return val
  //     },
  //     set: function (newVal) {
  //       if (newVal === val) return
  //       fn && fn(newVal)
  //       val = newVal
  //     },
  //   })
  // },
  globalData: {
    userInfo: null,
    request: utils.request,
    request_cydn: utils.request_cydn,
    longitude: "",
    latitude: "",
    getLocation: function (item = {
      type: "gcj02",
      success(res) {},
    }) {
      if (this.longitude !== "") {
        item.success({
          longitude: this.longitude,
          latitude: this.latitude
        })
      } else {
        wx.getLocation({
          type: "gcj02",
          success(res) {
            console.log(res);
            item.success(res)
          }
        })
      }

    },
    // 权限判断
    checkVipStatus: utils.checkVipStatus,
  },
  onShow: async function () {
    const tip = await utils.request(
      "/user/apply_wait_count", {},
      "POST"
    )
    console.log(tip, 'tip');
    if(tip.data) {
      setTimeout(() => {
        wx.showModal({
          title: '温馨提示',
          content: `您有${tip.data}条待审核的记录`,
          showCancel: true,
          confirmText: '前往',
          cancelText: '取消',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/sub_shenpi/shenpijilu/shenpijilu'
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          },
        })
      }, 2000);
    }
  }
})